package org.lc.cmd.plugin.scan;

import org.jline.utils.AttributedString;
import org.lc.cmd.ResultHandler;
import org.lc.cmd.util.CmdOutUtil;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 一些常用类型的处理
 */
@Component
@Order(100)
public class DefaultResultHandler implements ResultHandler {
    @Override
    public Object handle(Object result, String line) {
        if (result instanceof AttributedString) {
            CmdOutUtil.write((AttributedString) result, false);
            return null;
        }
        if (result instanceof String) {
            CmdOutUtil.write((String) result, false);
            return null;
        }
        if (result.getClass().isPrimitive()) {
            CmdOutUtil.write(result.toString(), false);
            return null;
        }
        return result;
    }
}
